package com.vr.xxaiagent.agent;

import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * ReAct(Reasoning and Acting 推理然后执行) 模式的代理类
 *
 * @author hzh
 * @date 2025/06/08
 */
@EqualsAndHashCode(callSuper = true)
@Data
public abstract class ReActAgent extends BaseAgent {

    /**
     * 思考当前状态并决定下一步是否执行
     *
     * @return boolean
     */
    public abstract boolean think();

    /**
     * 执行下一步
     * @return {@code String }
     */
    public abstract String act();

    /**
     * 执行单步步骤
     *
     * @return {@code String }
     */
    @Override
    protected String step() {
        try {
            boolean think = this.think();
            if (!think) {
                // 不需要执行下一步了
                return "思考完成-不需要行动";
            }
            return this.act();
        } catch (Exception e) {
            e.printStackTrace();
            return String.format("步骤执行失败: %s", e.getMessage());
        }
    }

}
